// pages/auth/index.js
//引入请求方法
import {request} from '../../request/index.js';
import regeneratorRuntime from '../../lib/runtime/runtime';
import { login } from "../../utils/asyncWx.js"

Page({

  //获取用户信息
 async handleGetUserInfo(e){
    try{
      //获取用户信息
      const {encryptedData,rawData,iv,signature} = e.detail;
      //获取小程序登录成功后的code
      const {code} = await login();
      //发送请求获取用户的token
      const {token} = await request({url:"https://api-hmugo-web.itheima.net/api/public/v1/users/wxlogin",data:{encryptedData,rawData,iv,signature,code},methods:"past"});
      //把token存到我们的缓存中 同时跳转回上个页面
      wx.setStorageSync("token", token);
      wx.navigateBack({
        delta: 1
      });
    }catch(err){
      console.log(err);
    }
      

  }
})